package ru.royalgatemagazine.app.show.main;

import java.util.ArrayList;
import java.util.List;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;

public class MainCatalogAdapter extends BaseAdapter {
	
	private final Context mContext;
	private final MainCatalogController mController;
	private final List<MainEntity> mList = new ArrayList<MainEntity>();
	
	public MainCatalogAdapter(Context context, MainCatalogController controller){
		mContext = context;
		mController = controller;
	}
	
	@Override
	public int getCount() {
		return mList.size();
	}

	@Override
	public Object getItem(int position) {
		return mList.get(position);
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parentView) {

		MainCatalogView item = null;
//		if (convertView == null) {
			item = new MainCatalogView(mContext, mController);
//		} else {
//			item = (MainCatalogView) convertView;
//		}
		item.clear();
		item.setEntity(mList.get(position));
		return item;
		
	}
	
	public void refresh(List<MainEntity> list){
		mList.clear();
		mList.addAll(list);
		notifyDataSetChanged();
	}
}
